package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: Sabrina
 * @Date:2025/06/15/20:55
 * @Description:
 */
@RestController(value = "adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "管理端-订单管理")
@Slf4j
public class OrderController {
    @Autowired
    private AdminOrderService adminOrderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result orderSearch(OrdersPageQueryDTO dto){

        PageResult result = adminOrderService.orderSearch(dto);
        return Result.success(result);
    }

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result getOrderById(@PathVariable Long id){
        OrderVO orderVO = adminOrderService.getOrderById(id);
        return Result.success(orderVO);
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO dto){//拒绝原因和订单id
        adminOrderService.cancel(dto);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        adminOrderService.rejection(dto);
        return Result.success();
    }

    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO dto){
        adminOrderService.confirm(dto);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliver(@PathVariable Long id){
        adminOrderService.deliver(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        adminOrderService.complete(id);
        return Result.success();
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result countOrders(){
        OrderStatisticsVO vo = adminOrderService.countOrders();
        return Result.success(vo);
    }


}
